package com.fz.controller.merchant;

import com.fz.aop.login.AnonymousAccess;
import com.fz.beans.PageBeans;
import com.fz.common.ResponseEntity;
import com.fz.dto.merchant.merRole.MerRoleAdd;
import com.fz.dto.merchant.merRole.MerRoleMenuDto;
import com.fz.dto.merchant.merRole.MerRoleQuery;
import com.fz.dto.merchant.merRole.MerRoleUpd;
import com.fz.service.merchant.MerRoleService;
import com.fz.vo.merchant.merMenu.MerMenuVo;
import com.fz.vo.merchant.merMenu.MerRoleMenuTreeVo;
import com.fz.vo.merchant.merRole.MerRoleVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "角色管理")
@RequestMapping("/merRole")
@ApiSort(value = 3)
@SuppressWarnings("unchecked")
public class MerRoleController {

    @Resource
    private MerRoleService merRoleService;

    @GetMapping("/findRoleList")
    @ApiOperation(value = "分页查询角色管理")
    @ApiOperationSupport(order = 1)
    @AnonymousAccess
    public ResponseEntity<MerRoleMenuTreeVo> findMerRoleList(MerRoleQuery merRoleQuery, PageBeans pageBeans) throws Exception{
        return merRoleService.findMerRoleList(pageBeans.getPageNum(),pageBeans.getPageSize(),merRoleQuery);
    }

    @GetMapping("/findMerMenuById")
    @ApiOperation(value = "根据角色查询菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId",value = "角色id", required = true,dataType = "Integer",paramType = "query")
    })
    @ApiOperationSupport(order = 3)
    @AnonymousAccess
    public ResponseEntity<List<MerMenuVo>> findMerMenuById(Integer roleId) throws Exception{
        return merRoleService.findMerMenuById(roleId);
    }

    @GetMapping("/findMerRoleSelect")
    @ApiOperation(value = "获取角色下拉框")
    @ApiOperationSupport(order = 2)
    @AnonymousAccess
    public ResponseEntity<List<MerRoleVo>> findMerRoleSelect(MerRoleQuery merRoleQuery) throws Exception{
        return merRoleService.findMerRoleSelect(merRoleQuery);
    }

    @PostMapping("/addMerRole")
    @ApiOperation(value = "新增角色")
    @ApiOperationSupport(order = 4)
    @AnonymousAccess
    public ResponseEntity addMerRole(@RequestBody MerRoleAdd merRoleAdd) throws Exception{
        return merRoleService.addMerRole(merRoleAdd);
    }

    @PostMapping("/updateMerRole")
    @ApiOperation(value = "修改角色")
    @ApiOperationSupport(order = 5)
    @AnonymousAccess
    public ResponseEntity updateMerRole(@RequestBody MerRoleUpd merRoleUpd) throws Exception{
        return merRoleService.updateMerRole(merRoleUpd);
    }

    @PostMapping("/saveMerRoleMenu")
    @ApiOperation(value = "保存角色菜单")
    @ApiOperationSupport(order = 6)
    @AnonymousAccess
    public ResponseEntity saveMerRoleMenu(@RequestBody MerRoleMenuDto merRoleMenuDto) throws Exception{
        return merRoleService.saveMerRoleMenu(merRoleMenuDto);
    }
}